{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 离散化处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额    柜台\n0    1001  张三  2019-03-01   9：00-14：00  1664.0   化妆品\n1    1002  李四  2019-03-01  14：00-21：00   954.0   化妆品\n2    1003  王五  2019-03-01   9：00-14：00  1407.0    食品\n3    1004  赵六  2019-03-01  14：00-21：00  1320.0    食品\n4    1005  周七  2019-03-01   9：00-14：00   994.0   日用品\n..    ...  ..         ...          ...     ...   ...\n244  1002  李四  2019-03-31  14：00-21：00   859.0  蔬菜水果\n245  1004  赵六  2019-03-31   9：00-14：00  1668.0   日用品\n246  1004  赵六  2019-03-31  14：00-21：00  1722.0   日用品\n247  1003  王五  2019-03-31   9：00-14：00  1274.0    食品\n248  1006  钱八  2019-03-31  14：00-21：00   812.0    食品\n\n[249 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1664.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>954.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1407.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1320.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>994.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>244</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>859.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>245</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1668.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1722.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>248</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>812.0</td>\n      <td>食品</td>\n    </tr>\n  </tbody>\n</table>\n<p>249 rows × 6 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "sales=pd.read_excel('./超市营业额2.xlsx','Sheet1')\n",
    "sales"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 等宽法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(40.953, 2462.4]     244\n(9690.6, 12100.0]      1\n(7281.2, 9690.6]       1\n(4871.8, 7281.2]       0\n(2462.4, 4871.8]       0\nName: 交易额, dtype: int64"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "c1=pd.cut(sales['交易额'],bins=5)\n",
    "c1.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 等频法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "0.0       53.0\n0.2      981.0\n0.4     1145.0\n0.6     1361.0\n0.8     1581.0\n1.0    12100.0\nName: 交易额, dtype: float64\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(1581.0, 12100.0]    49\n(1361.0, 1581.0]     49\n(1145.0, 1361.0]     49\n(981.0, 1145.0]      49\n(53.0, 981.0]        49\nName: 交易额, dtype: int64"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "def samefreq(data,k):\n",
    "    w=data.quantile(np.arange(0,1+1/k,1/k))\n",
    "    print(w)\n",
    "    return pd.cut(data,w)\n",
    "samefreq(sales['交易额'],5).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(52.999, 981.0]      50\n(1581.0, 12100.0]    49\n(1361.0, 1581.0]     49\n(1145.0, 1361.0]     49\n(981.0, 1145.0]      49\nName: 交易额, dtype: int64"
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "c2=pd.qcut(sales['交易额'],q=5)\n",
    "c2.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 随机抽样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额    柜台\n66   1004  赵六  2019-03-09   9：00-14：00  1683.0    食品\n163  1006  钱八  2019-03-21   9：00-14：00   807.0  蔬菜水果\n25   1002  李四  2019-03-04  14：00-21：00  1629.0   化妆品\n224  1006  钱八  2019-03-28  14：00-21：00  1219.0    食品\n229  1004  赵六  2019-03-29   9：00-14：00   910.0   日用品\n121  1002  李四  2019-03-16   9：00-14：00  1788.0   日用品\n222  1003  王五  2019-03-28  14：00-21：00  1210.0   日用品\n56   1003  王五  2019-03-08   9：00-14：00  1184.0   化妆品\n235  1005  周七  2019-03-30   9：00-14：00  1070.0  蔬菜水果\n115  1003  王五  2019-03-15   9：00-14：00  1483.0    食品",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>66</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-09</td>\n      <td>9：00-14：00</td>\n      <td>1683.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>163</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-21</td>\n      <td>9：00-14：00</td>\n      <td>807.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-04</td>\n      <td>14：00-21：00</td>\n      <td>1629.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>224</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-28</td>\n      <td>14：00-21：00</td>\n      <td>1219.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>229</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-29</td>\n      <td>9：00-14：00</td>\n      <td>910.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>121</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-16</td>\n      <td>9：00-14：00</td>\n      <td>1788.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>222</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-28</td>\n      <td>14：00-21：00</td>\n      <td>1210.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>56</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-08</td>\n      <td>9：00-14：00</td>\n      <td>1184.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>235</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-30</td>\n      <td>9：00-14：00</td>\n      <td>1070.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>115</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-15</td>\n      <td>9：00-14：00</td>\n      <td>1483.0</td>\n      <td>食品</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "sales.sample(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额    柜台\n7    1001  张三  2019-03-01  14：00-21：00  1442.0  蔬菜水果\n11   1004  赵六  2019-03-02  14：00-21：00   906.0    食品\n19   1004  赵六  2019-03-03  14：00-21：00  1236.0    食品\n25   1002  李四  2019-03-04  14：00-21：00  1629.0   化妆品\n31   1005  周七  2019-03-04  14：00-21：00  1199.0  蔬菜水果\n33   1002  李四  2019-03-05  14：00-21：00  1456.0   化妆品\n35   1004  赵六  2019-03-05  14：00-21：00   974.0    食品\n39   1001  张三  2019-03-05  14：00-21：00   856.0  蔬菜水果\n42   1003  王五  2019-03-06   9：00-14：00  1200.0    食品\n43   1004  赵六  2019-03-06  14：00-21：00  1245.0    食品\n48   1003  王五  2019-03-07   9：00-14：00  1713.0   化妆品\n50   1004  赵六  2019-03-07   9：00-14：00  1340.0    食品\n58   1004  赵六  2019-03-08   9：00-14：00  1073.0    食品\n71   1003  王五  2019-03-09  14：00-21：00  1670.0  蔬菜水果\n73   1001  张三  2019-03-10  14：00-21：00  1040.0   化妆品\n86   1003  王五  2019-03-11   9：00-14：00   801.0  蔬菜水果\n93   1005  周七  2019-03-12  14：00-21：00  1317.0   化妆品\n98   1003  王五  2019-03-13   9：00-14：00  1053.0    食品\n100  1004  赵六  2019-03-13   9：00-14：00  1130.0   化妆品\n102  1005  周七  2019-03-13   9：00-14：00  1047.0  蔬菜水果\n106  1002  李四  2019-03-14  14：00-21：00   822.0   日用品\n110  1005  周七  2019-03-14  14：00-21：00     NaN   化妆品\n112  1001  张三  2019-03-14  14：00-21：00  1261.0  蔬菜水果\n120  1001  张三  2019-03-15  14：00-21：00  1035.0  蔬菜水果\n129  1002  李四  2019-03-17   9：00-14：00   828.0   日用品\n135  1005  周七  2019-03-17   9：00-14：00  1022.0    食品\n139  1003  王五  2019-03-18   9：00-14：00  1210.0  蔬菜水果\n146  1003  王五  2019-03-19  14：00-21：00  1026.0   化妆品\n172  1002  李四  2019-03-22  14：00-21：00   864.0  蔬菜水果\n175  1006  钱八  2019-03-22   9：00-14：00  1503.0    食品\n178  1001  张三  2019-03-23  14：00-21：00  1271.0   化妆品\n184  1005  周七  2019-03-23  14：00-21：00  1523.0    食品\n188  1002  李四  2019-03-24  14：00-21：00  1793.0  蔬菜水果\n189  1003  王五  2019-03-24   9：00-14：00  1314.0   日用品\n191  1002  李四  2019-03-24   9：00-14：00  1285.0    食品\n192  1006  钱八  2019-03-24  14：00-21：00   966.0    食品\n195  1005  周七  2019-03-25   9：00-14：00   865.0  蔬菜水果\n196  1002  李四  2019-03-25  14：00-21：00  1647.0  蔬菜水果\n197  1003  王五  2019-03-25   9：00-14：00   958.0   日用品\n218  1001  张三  2019-03-28   9：00-14：00  1031.0   化妆品\n220  1002  李四  2019-03-28  14：00-21：00  1070.0  蔬菜水果\n221  1004  赵六  2019-03-28   9：00-14：00  1224.0   日用品\n225  1001  张三  2019-03-29  14：00-21：00  1523.0   化妆品\n228  1002  李四  2019-03-29  14：00-21：00  1063.0  蔬菜水果\n231  1003  王五  2019-03-29   9：00-14：00  1404.0    食品\n235  1005  周七  2019-03-30   9：00-14：00  1070.0  蔬菜水果\n239  1003  王五  2019-03-30   9：00-14：00  1032.0    食品\n241  1005  周七  2019-03-31  14：00-21：00  1321.0   化妆品\n246  1004  赵六  2019-03-31  14：00-21：00  1722.0   日用品\n247  1003  王五  2019-03-31   9：00-14：00  1274.0    食品",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>7</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1442.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-02</td>\n      <td>14：00-21：00</td>\n      <td>906.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-03</td>\n      <td>14：00-21：00</td>\n      <td>1236.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-04</td>\n      <td>14：00-21：00</td>\n      <td>1629.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>31</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-04</td>\n      <td>14：00-21：00</td>\n      <td>1199.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>33</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-05</td>\n      <td>14：00-21：00</td>\n      <td>1456.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>35</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-05</td>\n      <td>14：00-21：00</td>\n      <td>974.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>39</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-05</td>\n      <td>14：00-21：00</td>\n      <td>856.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>42</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-06</td>\n      <td>9：00-14：00</td>\n      <td>1200.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>43</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-06</td>\n      <td>14：00-21：00</td>\n      <td>1245.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>48</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-07</td>\n      <td>9：00-14：00</td>\n      <td>1713.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>50</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-07</td>\n      <td>9：00-14：00</td>\n      <td>1340.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>58</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-08</td>\n      <td>9：00-14：00</td>\n      <td>1073.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>71</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-09</td>\n      <td>14：00-21：00</td>\n      <td>1670.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>73</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-10</td>\n      <td>14：00-21：00</td>\n      <td>1040.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>86</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-11</td>\n      <td>9：00-14：00</td>\n      <td>801.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>93</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-12</td>\n      <td>14：00-21：00</td>\n      <td>1317.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>98</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-13</td>\n      <td>9：00-14：00</td>\n      <td>1053.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>100</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-13</td>\n      <td>9：00-14：00</td>\n      <td>1130.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>102</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-13</td>\n      <td>9：00-14：00</td>\n      <td>1047.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>106</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-14</td>\n      <td>14：00-21：00</td>\n      <td>822.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>110</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-14</td>\n      <td>14：00-21：00</td>\n      <td>NaN</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>112</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-14</td>\n      <td>14：00-21：00</td>\n      <td>1261.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>120</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-15</td>\n      <td>14：00-21：00</td>\n      <td>1035.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>129</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-17</td>\n      <td>9：00-14：00</td>\n      <td>828.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>135</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-17</td>\n      <td>9：00-14：00</td>\n      <td>1022.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>139</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-18</td>\n      <td>9：00-14：00</td>\n      <td>1210.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>146</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-19</td>\n      <td>14：00-21：00</td>\n      <td>1026.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>172</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-22</td>\n      <td>14：00-21：00</td>\n      <td>864.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>175</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-22</td>\n      <td>9：00-14：00</td>\n      <td>1503.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>178</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-23</td>\n      <td>14：00-21：00</td>\n      <td>1271.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>184</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-23</td>\n      <td>14：00-21：00</td>\n      <td>1523.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>188</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-24</td>\n      <td>14：00-21：00</td>\n      <td>1793.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>189</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-24</td>\n      <td>9：00-14：00</td>\n      <td>1314.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>191</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-24</td>\n      <td>9：00-14：00</td>\n      <td>1285.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>192</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-24</td>\n      <td>14：00-21：00</td>\n      <td>966.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>195</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-25</td>\n      <td>9：00-14：00</td>\n      <td>865.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>196</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-25</td>\n      <td>14：00-21：00</td>\n      <td>1647.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>197</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-25</td>\n      <td>9：00-14：00</td>\n      <td>958.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>218</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-28</td>\n      <td>9：00-14：00</td>\n      <td>1031.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>220</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-28</td>\n      <td>14：00-21：00</td>\n      <td>1070.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>221</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-28</td>\n      <td>9：00-14：00</td>\n      <td>1224.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>225</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-29</td>\n      <td>14：00-21：00</td>\n      <td>1523.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>228</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-29</td>\n      <td>14：00-21：00</td>\n      <td>1063.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>231</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-29</td>\n      <td>9：00-14：00</td>\n      <td>1404.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>235</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-30</td>\n      <td>9：00-14：00</td>\n      <td>1070.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>239</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-30</td>\n      <td>9：00-14：00</td>\n      <td>1032.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>241</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1321.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1722.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>食品</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "source": [
    "sales.sample(frac=0.2).sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额    柜台\n194  1001  张三  2019-03-25  14：00-21：00   114.0   化妆品\n55   1002  李四  2019-03-07  14：00-21：00   831.0  蔬菜水果\n152  1001  张三  2019-03-19  14：00-21：00   844.0    食品\n39   1001  张三  2019-03-05  14：00-21：00   856.0  蔬菜水果\n193  1004  赵六  2019-03-25   9：00-14：00   860.0   化妆品\n172  1002  李四  2019-03-22  14：00-21：00   864.0  蔬菜水果\n164  1002  李四  2019-03-21  14：00-21：00   888.0  蔬菜水果\n229  1004  赵六  2019-03-29   9：00-14：00   910.0   日用品\n130  1003  王五  2019-03-17  14：00-21：00   912.0   日用品\n118  1005  周七  2019-03-15  14：00-21：00   916.0   化妆品\n141  1004  赵六  2019-03-18   9：00-14：00   952.0   日用品\n197  1003  王五  2019-03-25   9：00-14：00   958.0   日用品\n4    1005  周七  2019-03-01   9：00-14：00   994.0   日用品\n125  1004  赵六  2019-03-16   9：00-14：00  1008.0   化妆品\n109  1004  赵六  2019-03-14   9：00-14：00  1026.0   化妆品\n60   1005  周七  2019-03-08   9：00-14：00  1029.0   日用品\n218  1001  张三  2019-03-28   9：00-14：00  1031.0   化妆品\n239  1003  王五  2019-03-30   9：00-14：00  1032.0    食品\n157  1001  张三  2019-03-20   9：00-14：00  1037.0   日用品\n67   1004  赵六  2019-03-09  14：00-21：00  1040.0    食品\n243  1005  周七  2019-03-31   9：00-14：00  1044.0  蔬菜水果\n237  1001  张三  2019-03-30   9：00-14：00  1086.0   日用品\n70   1006  钱八  2019-03-09   9：00-14：00  1118.0  蔬菜水果\n46   1006  钱八  2019-03-06   9：00-14：00  1162.0  蔬菜水果\n200  1006  钱八  2019-03-25  14：00-21：00  1178.0    食品\n56   1003  王五  2019-03-08   9：00-14：00  1184.0   化妆品\n222  1003  王五  2019-03-28  14：00-21：00  1210.0   日用品\n139  1003  王五  2019-03-18   9：00-14：00  1210.0  蔬菜水果\n24   1001  张三  2019-03-04   9：00-14：00  1216.0   化妆品\n242  1002  李四  2019-03-31   9：00-14：00  1274.0   化妆品\n3    1004  赵六  2019-03-01  14：00-21：00  1320.0    食品\n153  1002  李四  2019-03-20   9：00-14：00  1332.0   化妆品\n133  1004  赵六  2019-03-17   9：00-14：00  1336.0   化妆品\n9    1002  李四  2019-03-02  14：00-21：00  1395.0   化妆品\n7    1001  张三  2019-03-01  14：00-21：00  1442.0  蔬菜水果\n12   1005  周七  2019-03-02   9：00-14：00  1444.0   日用品\n21   1006  钱八  2019-03-03  14：00-21：00  1457.0   日用品\n145  1002  李四  2019-03-19   9：00-14：00  1459.0   化妆品\n52   1005  周七  2019-03-07   9：00-14：00  1465.0   日用品\n179  1006  钱八  2019-03-23   9：00-14：00  1496.0  蔬菜水果\n123  1003  王五  2019-03-16   9：00-14：00  1498.0    食品\n225  1001  张三  2019-03-29  14：00-21：00  1523.0   化妆品\n161  1002  李四  2019-03-21   9：00-14：00  1528.0   化妆品\n20   1005  周七  2019-03-03   9：00-14：00  1592.0   日用品\n156  1002  李四  2019-03-20  14：00-21：00  1615.0  蔬菜水果\n226  1002  李四  2019-03-29   9：00-14：00  1624.0   化妆品\n85   1005  周七  2019-03-11  14：00-21：00  1633.0   化妆品\n14   1002  李四  2019-03-02   9：00-14：00  1649.0  蔬菜水果\n0    1001  张三  2019-03-01   9：00-14：00  1664.0   化妆品\n34   1003  王五  2019-03-05   9：00-14：00  1687.0    食品",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>194</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-25</td>\n      <td>14：00-21：00</td>\n      <td>114.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>55</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-07</td>\n      <td>14：00-21：00</td>\n      <td>831.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>152</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-19</td>\n      <td>14：00-21：00</td>\n      <td>844.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>39</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-05</td>\n      <td>14：00-21：00</td>\n      <td>856.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>193</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-25</td>\n      <td>9：00-14：00</td>\n      <td>860.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>172</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-22</td>\n      <td>14：00-21：00</td>\n      <td>864.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>164</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-21</td>\n      <td>14：00-21：00</td>\n      <td>888.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>229</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-29</td>\n      <td>9：00-14：00</td>\n      <td>910.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>130</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-17</td>\n      <td>14：00-21：00</td>\n      <td>912.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>118</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-15</td>\n      <td>14：00-21：00</td>\n      <td>916.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>141</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-18</td>\n      <td>9：00-14：00</td>\n      <td>952.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>197</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-25</td>\n      <td>9：00-14：00</td>\n      <td>958.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>994.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>125</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-16</td>\n      <td>9：00-14：00</td>\n      <td>1008.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>109</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-14</td>\n      <td>9：00-14：00</td>\n      <td>1026.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>60</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-08</td>\n      <td>9：00-14：00</td>\n      <td>1029.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>218</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-28</td>\n      <td>9：00-14：00</td>\n      <td>1031.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>239</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-30</td>\n      <td>9：00-14：00</td>\n      <td>1032.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>157</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-20</td>\n      <td>9：00-14：00</td>\n      <td>1037.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>67</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-09</td>\n      <td>14：00-21：00</td>\n      <td>1040.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>243</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1044.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>237</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-30</td>\n      <td>9：00-14：00</td>\n      <td>1086.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>70</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-09</td>\n      <td>9：00-14：00</td>\n      <td>1118.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>46</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-06</td>\n      <td>9：00-14：00</td>\n      <td>1162.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>200</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-25</td>\n      <td>14：00-21：00</td>\n      <td>1178.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>56</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-08</td>\n      <td>9：00-14：00</td>\n      <td>1184.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>222</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-28</td>\n      <td>14：00-21：00</td>\n      <td>1210.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>139</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-18</td>\n      <td>9：00-14：00</td>\n      <td>1210.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>24</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-04</td>\n      <td>9：00-14：00</td>\n      <td>1216.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>242</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1320.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>153</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-20</td>\n      <td>9：00-14：00</td>\n      <td>1332.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>133</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-17</td>\n      <td>9：00-14：00</td>\n      <td>1336.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-02</td>\n      <td>14：00-21：00</td>\n      <td>1395.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1442.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-02</td>\n      <td>9：00-14：00</td>\n      <td>1444.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>21</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-03</td>\n      <td>14：00-21：00</td>\n      <td>1457.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>145</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-19</td>\n      <td>9：00-14：00</td>\n      <td>1459.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>52</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-07</td>\n      <td>9：00-14：00</td>\n      <td>1465.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>179</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-23</td>\n      <td>9：00-14：00</td>\n      <td>1496.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>123</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-16</td>\n      <td>9：00-14：00</td>\n      <td>1498.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>225</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-29</td>\n      <td>14：00-21：00</td>\n      <td>1523.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>161</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-21</td>\n      <td>9：00-14：00</td>\n      <td>1528.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-03</td>\n      <td>9：00-14：00</td>\n      <td>1592.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>156</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-20</td>\n      <td>14：00-21：00</td>\n      <td>1615.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>226</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-29</td>\n      <td>9：00-14：00</td>\n      <td>1624.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>85</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-11</td>\n      <td>14：00-21：00</td>\n      <td>1633.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-02</td>\n      <td>9：00-14：00</td>\n      <td>1649.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>0</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1664.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>34</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-05</td>\n      <td>9：00-14：00</td>\n      <td>1687.0</td>\n      <td>食品</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 16
    }
   ],
   "source": [
    "sales.sample(frac=0.2).sort_values(by='交易额')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 重采样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "DatetimeIndex(['2000-01-01 00:00:00', '2000-01-01 00:01:00',\n               '2000-01-01 00:02:00', '2000-01-01 00:03:00',\n               '2000-01-01 00:04:00', '2000-01-01 00:05:00',\n               '2000-01-01 00:06:00', '2000-01-01 00:07:00',\n               '2000-01-01 00:08:00'],\n              dtype='datetime64[ns]', freq='T')"
     },
     "metadata": {},
     "execution_count": 17
    }
   ],
   "source": [
    "index=pd.date_range('1/1/2000',periods=9,freq='T')\n",
    "index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "2000-01-01 00:00:00    0\n2000-01-01 00:01:00    1\n2000-01-01 00:02:00    2\n2000-01-01 00:03:00    3\n2000-01-01 00:04:00    4\n2000-01-01 00:05:00    5\n2000-01-01 00:06:00    6\n2000-01-01 00:07:00    7\n2000-01-01 00:08:00    8\nFreq: T, dtype: int64"
     },
     "metadata": {},
     "execution_count": 18
    }
   ],
   "source": [
    "series=pd.Series(range(9),index=index)\n",
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "2000-01-01 00:00:00     3\n2000-01-01 00:03:00    12\n2000-01-01 00:06:00    21\nFreq: 3T, dtype: int64"
     },
     "metadata": {},
     "execution_count": 20
    }
   ],
   "source": [
    "series.resample('3T').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "2000-01-01 00:03:00     3\n2000-01-01 00:06:00    12\n2000-01-01 00:09:00    21\nFreq: 3T, dtype: int64"
     },
     "metadata": {},
     "execution_count": 21
    }
   ],
   "source": [
    "series.resample('3T',label='right').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "1999-12-31 23:57:00     0\n2000-01-01 00:00:00     6\n2000-01-01 00:03:00    15\n2000-01-01 00:06:00    15\nFreq: 3T, dtype: int64"
     },
     "metadata": {},
     "execution_count": 22
    }
   ],
   "source": [
    "series.resample('3T',label='left',closed='right').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "2000-01-01 00:00:00    0\n2000-01-01 00:00:30    0\n2000-01-01 00:01:00    1\n2000-01-01 00:01:30    1\n2000-01-01 00:02:00    2\n2000-01-01 00:02:30    2\n2000-01-01 00:03:00    3\n2000-01-01 00:03:30    3\n2000-01-01 00:04:00    4\n2000-01-01 00:04:30    4\n2000-01-01 00:05:00    5\n2000-01-01 00:05:30    5\n2000-01-01 00:06:00    6\n2000-01-01 00:06:30    6\n2000-01-01 00:07:00    7\n2000-01-01 00:07:30    7\n2000-01-01 00:08:00    8\nFreq: 30S, dtype: int64"
     },
     "metadata": {},
     "execution_count": 24
    }
   ],
   "source": [
    "series.resample('30s').ffill()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "sales['日期']=pd.to_datetime(sales['日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名         日期           时段     交易额    柜台\n0    1001  张三 2019-03-01   9：00-14：00  1664.0   化妆品\n1    1002  李四 2019-03-01  14：00-21：00   954.0   化妆品\n2    1003  王五 2019-03-01   9：00-14：00  1407.0    食品\n3    1004  赵六 2019-03-01  14：00-21：00  1320.0    食品\n4    1005  周七 2019-03-01   9：00-14：00   994.0   日用品\n..    ...  ..        ...          ...     ...   ...\n244  1002  李四 2019-03-31  14：00-21：00   859.0  蔬菜水果\n245  1004  赵六 2019-03-31   9：00-14：00  1668.0   日用品\n246  1004  赵六 2019-03-31  14：00-21：00  1722.0   日用品\n247  1003  王五 2019-03-31   9：00-14：00  1274.0    食品\n248  1006  钱八 2019-03-31  14：00-21：00   812.0    食品\n\n[249 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1664.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>954.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1407.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1320.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>994.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>244</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>859.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>245</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1668.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1722.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>248</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>812.0</td>\n      <td>食品</td>\n    </tr>\n  </tbody>\n</table>\n<p>249 rows × 6 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 31
    }
   ],
   "source": [
    "sales.resample(freq=)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}